package com.ed100.sass.nio;

import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class BufferTest {

	public static void main(String[] args) throws Exception {
		RandomAccessFile aFile = new RandomAccessFile("/Users/jackey/Downloads/temp/BlackListCom.java", "rw");
		FileChannel fChannel = aFile.getChannel();

		ByteBuffer buf = ByteBuffer.allocate(48);

		int byteRead = fChannel.read(buf);
		while (byteRead != -1) {

			buf.flip();
			while (buf.hasRemaining()) {
				System.out.print((char) buf.get());
			}

			buf.clear(); //make buffer ready for writing
			byteRead = fChannel.read(buf);
		}
		aFile.close();
	}

}
